<!--
 * 配置管理
 * @author luguoxiang
 * @date 2023-03-27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <lg-table :schema="fieldList" v-bind="tableProps" actionbar>
    <template #toolbar-left>
      <t-button v-if="has('create')" @click="editRef.open()">新增</t-button>
      <t-button v-if="has('clear-cache')" theme="default" title="清空数据缓存" @click="clearCache">
        清空缓存
      </t-button>
    </template>
    <template #actionbar="{ row }">
      <btn-row-update v-if="has('update')" @click="editRef.open(row)" />
      <btn-row-remove v-if="has('remove')" @click="remove(row.id)" />
    </template>
  </lg-table>
  <edit ref="editRef" @ok="reload(1)" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { LgTable, useAuth, useTable } from '@/soar';
import api from '@/api/sysConfig';
import fieldList from './schema';
import Edit from './Edit.vue';

const { has } = useAuth();
const editRef = ref();

const { tableProps, remove, reload } = useTable<any>({
  api,
  rowKey: 'id',
});

function clearCache() {
  api.clearCache();
}
</script>
